const connection = require('../app/database')
class CollegeService {
  async getCollegeList(pagenum='1', pagesize='10', name='') {
    const statement = `		
      SELECT (SELECT COUNT(*) FROM colleges) totalCount,
      JSON_ARRAYAGG(JSON_OBJECT('id',c.college_id,'name',c.college_name)) list
      FROM (SELECT * FROM colleges 
      WHERE college_name LIKE '%${name}%'
      LIMIT ?,?) c;
    `
    const offset = (pagenum - 1) * pagesize
    const [res] = await connection.execute(statement,[offset+'',pagesize])
    return res[0]
  }
}
module.exports = new CollegeService()